#include "graph.h"

int main(int argc,char *argv[])
{
  Graph mygraph;

  read_graph(&mygraph,argv[1]);

  /* you take it from here */
 
  print_graph(&mygraph);
  int valueMix = mygraph.table[1].outdegree;
  char* namesMix = mygraph.table[1].name;
  
  int valueMin = mygraph.table[1].outdegree;
  char* namesMin = mygraph.table[1].name;
  for(int i = 2; i < mygraph.MaxSize + 1; i++)
  {
    if(valueMix < (mygraph.table[i].outdegree))
    {
      namesMix = mygraph.table[i].name;
      valueMix = mygraph.table[i].outdegree;
    }
    if(mygraph.table[i].outdegree != 0)
    {
      if((valueMin > mygraph.table[i].outdegree) || valueMin == 0)
      {
          namesMin = mygraph.table[i].name;
          valueMin = mygraph.table[i].outdegree;
      }//if
    }//if
  }//for
  if(valueMix == 0)
  {
    printf("There is no largest out-degree Node\n");
  }
  else
  {
    printf("The largest out-degree Node is %s\n",namesMix );
  }
  if(valueMin == 0)
  {
    printf("There is no smallest out-degree Node\n\n");
  }
  else
  {
    printf("The smallest out-degree Node is %s\n\n",namesMin );
  }
  int listIn[mygraph.MaxSize + 1];
  
  int valueMixIn = 0;
  int recordMixIn = 0;
  
  int valueMinIn = 0;
  int recordMinIn = 0;
  
  
  for(int j = 0; j < mygraph.MaxSize + 1; j++)
  {
    listIn[j] = 0;
  }
  
  
  for(int i = 1; i <mygraph.MaxSize + 1; i++)
  { 
    List* testGraph = mygraph.table[i].outlist;    
    while(testGraph != NULL)
    {
      listIn[testGraph -> index] += 1;
      testGraph = testGraph -> next;	  
    }//while
  }//for
  valueMinIn = listIn[1];
  for(int i = 1; i < mygraph.MaxSize + 1; i++)
  {
    if(valueMixIn < listIn[i])
    {
      recordMixIn = i;
      valueMixIn = listIn[i];
    }        
    if((valueMinIn > listIn[i] || valueMinIn == 0) && listIn[i] != 0)
    {
      recordMinIn = i;
      valueMinIn = listIn[i];
    }
  }
  if(valueMixIn == 0)
  {
    printf("There is no largest in-degree Node");
  }
  else
  {
    printf("The largest in-degree Node is %s\n",mygraph.table[recordMixIn].name);
  }
  if(valueMinIn == 0)
  {
    printf("There is no smallest in-degree Node\n");
  }
  else
  {
    printf("The smallest in-degree Node is %s\n",mygraph.table[recordMinIn].name);
  }  
  return(0);
}
